package club.xinghe.servlet.teacher;

import club.xinghe.biz.TkBiz;
import club.xinghe.entity.Style;
import club.xinghe.entity.Teacher;
import club.xinghe.entity.Tk;
import club.xinghe.entity.Zy;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.List;

/**
 * 向题库中添加试题
 * @刘艺广
 */
@WebServlet("/teacher/AddTkServlet")
public class AddTkServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //得到老师在文本框中输入的试题：问题，选项，答案
        int styleId=Integer.parseInt(request.getParameter("styleId"));
        String  tContent= request.getParameter("addTkString");
        String tAnswer=request.getParameter("addAnswer");

        HttpSession session=request.getSession();
        //得到老师所在专业的id
        Teacher teacher= (Teacher) session.getAttribute("teacher");
        int zId=teacher.getZy().getzId();

        Zy zy=new Zy(zId);
        Style style=new Style(styleId);
        Tk tk=new Tk(tContent,tAnswer,zy,style);
        TkBiz tkBiz=new TkBiz();
        int result=tkBiz.addTk(tk);
        PrintWriter out=response.getWriter();
        if(result>0){
            out.print("true");
        }else{
            out.print("false");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
